package com.lc.afbx.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.fragment.FragmentBusinessJoinBusiness;
import com.lc.afbx.fragment.FragmentBusinessJoinStore;

/**
 * Created by Administrator on 2016/5/19.
 */
public class BusinessJoinActivity extends BaseActivity implements View.OnClickListener {


    private TextView business_join_xuanchuan;
    private TextView business_join_baoxian;

    private Fragment[] fragments;
    private FragmentBusinessJoinBusiness fragmentBusinessJoinBusiness;
    private FragmentBusinessJoinStore fragmentBusinessJoinStore;
    private int index;
    private int prePosition;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_join);

        business_join_xuanchuan = ((TextView) findViewById(R.id.business_join_xuanchuan));
        business_join_baoxian = ((TextView) findViewById(R.id.business_join_baoxian));

        fragmentBusinessJoinBusiness = new FragmentBusinessJoinBusiness();

        fragmentBusinessJoinStore = new FragmentBusinessJoinStore();

        fragments = new Fragment[]{fragmentBusinessJoinBusiness, fragmentBusinessJoinStore};

        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container_rl, fragmentBusinessJoinBusiness)
                .show(fragmentBusinessJoinBusiness).commit();

        business_join_xuanchuan.setOnClickListener(this);
        business_join_baoxian.setOnClickListener(this);

    }


    @Override
    public void onClick(View view) {

        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;


            case R.id.business_join_xuanchuan:

                index = 0;

                if (index != prePosition) {

                    business_join_xuanchuan.setTextColor(getResources().getColor(R.color.shangjairuzhu_selected));
                    business_join_baoxian.setTextColor(getResources().getColor(R.color.shangjairuzhu_unselected));

                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {
                        trx.add(R.id.fragment_container_rl, fragments[index]);
                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;

                }

                return;

            case R.id.business_join_baoxian:

                index = 1;

                if (index != prePosition) {

                    business_join_xuanchuan.setTextColor(getResources().getColor(R.color.shangjairuzhu_unselected));
                    business_join_baoxian.setTextColor(getResources().getColor(R.color.shangjairuzhu_selected));

                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {
                        trx.add(R.id.fragment_container_rl, fragments[index]);
                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;

                }

                return;

        }

    }

}
